/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * NuGat-API named Chameleon developed by Simon De Baets to Verimag.
 *
 */
package chameleon.view.command;

import chameleon.model.game.Game;
import chameleon.view.OutputManager;
import chameleon.view.input.Input;

/**
 * This command is not a user command but an internal Command. This command checks
 * if necessary elements to use a command are present in the structure.
 * 
 * This command has different levels : 
 *  1) a smv file is present
 *  2) a manager is present
 * 
 * @author simon
 */
public class InternalCheckCommand {
    
    private int level_;
    private Input input_;
    
    public InternalCheckCommand(Input input, int level){
        input_ = input;
        level_ = level;
    }
    
    /**
     * This command checks if the necessary elements are present in the input.
     * 
     * This command has different levels : 
     *  1) a smv file is present
     *  2) a manager is present
     *  3) a strategy is present
     * 
     * Note this property is recursive, a level 3 must have an smv file and a model
     * @return 
     */
    
    public boolean isOk(){
        OutputManager output = new OutputManager();
        if (level_ == 1){
            if (input_.getSmvFile() != null)
                return true;
            else{
                output.displayString("No input file is present, please use read_model before!\n");
                return false ;
            }
        }
        else if (level_ == 2){
            InternalCheckCommand check = new InternalCheckCommand(input_, 1);
            if (check.isOk()){
                if (input_.getManager() != null)
                    return true;
                else{
                    output.displayString("No model is present please use build_model before\n!");
                    return false ;
                }
            }
            else
                return false;
        }
        else if (level_ == 3){
            InternalCheckCommand check = new InternalCheckCommand(input_,2);
            if (check.isOk()){
                Game game = input_.getManager().getGame();
                if(game.getStrategy() != null)
                    return true;
                else{
                    output.displayString("No strategy is present please compute a strategy before\n!");
                    return false ;
                }
            }
            else
                return false;
        }
        else
            throw new RuntimeException("InternalCheckCommand :: Unknow level of checking");
    }
    
}
